<?php
//time start
$GLOBALS['time_start'] = microtime(1);
//

//get rid off notices
@error_reporting(E_ALL ^ E_NOTICE);

//include configuration file
if(!file_exists('includes/conf_'.$_GET['conf'].'.php') or !is_numeric($_GET['conf']))
	$_GET['conf']='conf.php';
else $_GET['conf']='conf_'.$_GET['conf'].'.php';

if(!file_exists('includes/'.$_GET['conf'])) {
	header('location: install.php');
	exit;
}

$c=include('includes/'.$_GET['conf']);
//

//display errors
if($conf['display_errors']) @ini_set("display_errors", 1);
else @ini_set("display_errors", 0);

//let default_charset be set by client
@ini_set("default_charset", ""); 

//cookie domain
if($conf['cookie_domain']) session_set_cookie_params(0, NULL, $conf['cookie_domain']);

//session start
session_name($conf['session_name']);
session_start();

//theme
if(!$_SESSION['theme'])
	$_SESSION['theme']=$conf['theme'];
if($_GET['theme'] && file_exists('./themes/'.$_GET['theme'].'/') && strpos($_GET['theme'], '.')===false)
	$_SESSION['theme']=$_GET['theme'];
//theme end

//language pre function
if(!$_SESSION['lang_short'])
	$_SESSION['lang_short'] = $conf['language'];
//

//accept language
if(!$_SESSION['ACCEPT_LANGUAGE']) {
	$_SESSION['ACCEPT_LANGUAGE']=explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
	foreach($_SESSION['ACCEPT_LANGUAGE'] as $k=>$v) {
		$_SESSION['ACCEPT_LANGUAGE'][$k]=explode(";", $v);
		$_SESSION['ACCEPT_LANGUAGE'][$k]=$_SESSION['ACCEPT_LANGUAGE'][$k][0];
	}
}
//

//functions inclusion
include('includes/functions.php');
if($_POST['module'])
	$_GET['module']=$_POST['module'];
//

//getting permission table
get_permission_table();
//

//processing $_POST $_GET $_REQUEST
changeGETPOST();
//


{
	//language post function
	$languages=get_lang_list();
	if(in_array($_GET['lang'], $languages))
		$_SESSION['lang_short']=$_GET['lang'];
	//

	//recovery array (we save some var to recover them when go through error)
	{
		$recover_arr=array('text', 'name', 'path', 'title');
		$recover_arrl=array('desc_', 'name_', 'text_', 'title_');
		foreach($languages as $lang) {
			foreach($recover_arrl as $item)	$recover_arr[]=$item.$lang;
		}
		foreach ($recover_arr as $ra)
			if($_POST[$ra])
				$_SESSION['recover_'.$ra]=$_POST[$ra];
	}
	//
}

//theme_path
$GLOBALS['theme_path']='themes/'.$_SESSION['theme'].'/';
include($GLOBALS['theme_path'].'gfx/images.php');

//language
$GLOBALS['lang']=array(array());
get_lang();
if(!empty($GLOBALS['lang'][$_GET['module']]['site_title'])) {
	$GLOBALS['lang']['global']['site_title']=$GLOBALS['lang'][$_GET['module']]['site_title'];
}
if(!empty($GLOBALS['lang'][$_GET['module']]['site_description'])) {
	$GLOBALS['lang']['global']['site_description']=$GLOBALS['lang'][$_GET['module']]['site_description'];
}
if(!empty($GLOBALS['lang'][$_GET['module']]['site_keywords'])) {
	$GLOBALS['lang']['global']['site_keywords']=$GLOBALS['lang'][$_GET['module']]['site_keywords'];
}
//

?>
